package com.example.leetcode.solution;

import com.example.leetcode.ListNode;

public class Solution206 {

    public static void main(String[] args) {
        ListNode head = new ListNode(1,new ListNode(2,new ListNode(3,new ListNode(4,new ListNode(5)))));
        new Solution206().reverseList(head);
    }

    public ListNode reverseList(ListNode head) {
        if(head == null){
            return null;
        }
        ListNode newHead = new ListNode(head.val);
        while(head.next != null){
            ListNode next = head.next;
            ListNode temp = newHead;
            newHead = new ListNode(next.val);;
            newHead.next = temp;
            head = next;
        }
        return newHead;
    }
}
